<template>
    <!-- homeSub/pages/activePage/activePage.wxml -->
    <view>
        <view v-if="activityStatus == 0">
            <view class="imagesize">
                <image class="upgrading" src="https://oos-cn.ctyunapi.cn/front-end/static/homeSub/images/activityStart.png" mode=""></image>
            </view>
            <view class="txt">
                <view class="txt1">
                    活动开始时间
                    <text class="fromDate">{{ fromDate }}</text>
                    敬请期待！
                </view>
            </view>
        </view>
        <view class="header" v-if="activityStatus == 1">
            <image class="header-image" src="https://oos-cn.ctyunapi.cn/front-end/static/homeSub/images/bg.png"></image>
            <image src="https://oos-cn.ctyunapi.cn/front-end/static/homeSub/images/title_img.png" class="title_img"></image>
            <view class="header-title">
                <view>老用户邀请新用户充值、消费后</view>
                <view class="service-wrap">
                    <text>老用户获得</text>
                    <text class="wallet">{{ oldMemberBalance ? oldMemberBalance : 0 }}元</text>
                    <text class="service" v-if="couponType">{{ couponType }}</text>
                </view>
            </view>
            <!-- 已邀请好友列表 -->
            <view class="friendsList-wrap">
                <view class="friendsList">
                    <!-- #ifdef APP-PLUS  -->
					<button class="rightnow-btn" @click="appShare('WXSceneSession')">立即邀请</button>
					<!-- #endif -->
					<!-- #ifdef MP-WEIXIN  -->
                    <button open-type="share" class="rightnow-btn">立即邀请</button>
                    <!-- #endif -->
                    <image src="https://oos-cn.ctyunapi.cn/front-end/static/homeSub/images/line_bg.png" class="line_bg"></image>
                    <text class="line_text">已邀请好友列表</text>
                    <view class="friendsNum">
                        <view class="friendsNum-left">
                            <view class="num-label">当前获得奖励总数</view>
                            <view class="nums">
                                <text class="num">{{ memberCouponBalance }}</text>
                                <text class="unit">元</text>
                            </view>
                        </view>
                        <view class="friendsNum-right">
                            <view class="num-label">共邀请人数</view>
                            <view class="nums">
                                <text class="num">{{ inviteMemberSize }}</text>
                                <text class="unit">人</text>
                            </view>
                        </view>
                    </view>
                    <view class="invitationInfo">
                        <view>邀请名单</view>
                        <view>获得奖励</view>
                    </view>
                    <scroll-view :scroll-y="true" style="height: 630rpx" v-if="inviteMemberList.length">
                        <view class="invitationList" v-for="(item, index) in inviteMemberList" :key="index">
                            <view class="phone">
                                {{ item.telephone }}
                            </view>

                            <view class="reward-txt">
                                获得
                                <text class="reward">{{ item.couponBalance }}</text>
                                元
                            </view>
                        </view>
                    </scroll-view>
                    <view v-else class="invitationList-none">暂无好友名单,快去邀请吧</view>
                </view>
            </view>
        </view>
        <view v-if="activityStatus == 2">
            <view class="imagesize">
                <image class="upgrading" src="https://oos-cn.ctyunapi.cn/front-end/static/homeSub/images/activityOver.png" mode=""></image>
            </view>
            <view class="txt">
                <view class="txt1">哎呀！来晚了，活动结束了~</view>
            </view>
        </view>
    </view>
</template>

<script>
// homeSub/pages/activePage/activePage.ts
'use strict';
import Upgrading from '../../../components/upgrading/upgrading';

// exports.__esModule = true;

var https_1 = require('./../../../api/https.js');
var newapp = getApp();
var app = getApp();
export default {
    components: {
        Upgrading
    },
    data() {
        return {
            // inviteMemberList:[
            //     {
            //         reward:'5',
            //         phone:'139*****013'
            //     },
            //     {
            //         reward:'5',
            //         phone:'139*****013'
            //     },
            //     {
            //         reward:'5',
            //         phone:'139*****013'
            //     },
            //     {
            //         reward:'5',
            //         phone:'139*****013'
            //     },
            //     {
            //         reward:'5',
            //         phone:'139*****013'
            //     },
            //     {
            //         reward:'5',
            //         phone:'139*****013'
            //     },
            //     {
            //         reward:'5',
            //         phone:'139*****013'
            //     }
            // ],
            inviteMemberList: [],
            oldMemberBalance: 0,
            inviteMemberSize: 0,
            memberCouponBalance: 0,
            inviterMemberId: null,
            couponType: '',
            activityStatus: null,
            fromDate: null ,// 活动开始时间
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
        this.getOldAndNewBenifit();
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        var memberId = uni.getStorageSync('memberId');
		const name = app.globalData.wxAppName
        return {   
            title: `帮我点一下,一起来${name}享受充电优惠吧!`,      
            path: '/homeSub/pages/registration/registration?memberId=' + memberId,
            imageUrl: 'https://oos-cn.ctyunapi.cn/front-end/static/homeSub/images/share.png'
        };
    },
    methods: {   
        //分享微信好友
			appShare(scene) {
				let that = this
				const memberId = wx.getStorageSync('memberId')
                const name = app.globalData.wxAppName
				var img="https://oos-cn.ctyunapi.cn/front-end/static/homeSub/images/share.jpg"
				var url1=newapp.globalData.imgUrl
				var shareText = `帮我点一下,一起来${name}享受充电优惠吧!`
				var sellerId=newapp.globalData.sellerId
				var sellerNo=newapp.globalData.sellerNo
				var sourceType=0// ios0 安卓1
				// var platform=uni.getSystemInfoSync().platform
				//     if(platform=='ios'){
				//           sourceType=0
				//     }else if(platform=='android'){
				//           sourceType=1
				//     }

				var shareUrl=`${url1}/activityPage/zhuceActive.html?memberId=${memberId}&sellerId=${sellerId}&sellerNo=${sellerNo}&sourceType=${sourceType}`
				uni.share({
					provider: "weixin", //分享服务提供商（即weixin|qq|sinaweibo）
					scene: scene, //场景，可取值参考下面说明。
					type: 0, //分享形式
					href: shareUrl, //跳转链接
					title: shareText, //分享内容的标题
					// summary: '', //分享内容的摘要
					imageUrl: img, //图片地址
					success: function(res) {
						console.log("分享成功",res)
					},
					fail: function(err) {
						uni.showToast({
							title: '分享失败',
							icon: 'none',
							duration: 2000
						})
					}
				});
			},
        getOldAndNewBenifit: function () {
            var that = this;
            var tmp = this;
            https_1
                .getOldAndNewBenifit2({
					sellerId: newapp.globalData.sellerId
				})
                .then(function (res) {
                    if (res.code == 0) {
                        var oldMemberBalance = parseInt(res.data.oldMemberBalance) / 100;
                        var couponType = Array.from(new Set(res.data.couponTypeList)).join('、');
                        tmp.oldMemberBalance=oldMemberBalance,
                            tmp.couponType=couponType,
                            tmp.activityStatus=res.data.activityStatus,
                            tmp.fromDate=res.data.fromDate

                        if (that.activityStatus == 1) {
                            that.getInviteMemberList(); // this.getCodeAndCheckRegister()
                        }
                    }
                })
                ['catch'](function (err) {
                    console.log(err);
                });
        },

        getInviteMemberList: function () {
            var that = this;
            var memberId = uni.getStorageSync('memberId');
            https_1
                .getInviteMemberList({
                    sellerId: newapp.globalData.sellerId,
                    memberId: memberId
                })
                .then(function (res) {
                    if (res.code == 0) {
                        var friends = res.data.inviteMemberList;
                        friends.forEach(function (element) {
                            element.telephone = element.telephone.slice(0, 3) + '******' + element.telephone.slice(7, 11);
                            element.oldMemberBalance = (element.oldMemberBalance / 100).toFixed(2);
                            element.couponBalance = (element.couponBalance / 100).toFixed(2);
                        });
                        var memberCouponBalance = parseInt(res.data.memberCouponBalance) / 100;
                        that.inviteMemberList=friends,
                            that.inviteMemberSize=res.data.inviteMemberSize,
                            that.memberCouponBalance=memberCouponBalance
                    }
                })
                ['catch'](function (err) {
                    console.log(err);
                });
        },

        getCodeAndCheckRegister: function () {
            var openId = uni.getStorageSync('openid');
            var tel = uni.getStorageSync('tel');
            var memberId = uni.getStorageSync('memberId');
            var that = this;
            https_1
                .getCodeAndCheckRegister({
                    phoneNo: parseInt(tel),
                    sellerId: newapp.globalData.sellerId,
                    sellerNo: app.globalData.sellerNo,
                    sourceType: 3,
                    inviterMemberId: memberId,
                    openId: openId
                })
                .then(function (res) {
                    if (res.code == 0) {
                        that.inviterMemberId=res.data.inviterMemberId
                    }
                })
                ['catch'](function (err) {
                    console.log(err);
                });
        }
    }
};
</script>
<style lang="less">
/* homeSub/pages/activePage/activePage.wxss */
@import "./activePage.less";
</style>
